home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15074 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Square of a floating point number.
  5. Date: 16 Apr 1996 15:00:35 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l15a3INNcfo@keats.ugrad.cs.ubc.ca>
  8. References: <Dpo0Mn.DEo@ireq.hydro.qc.ca> <3172ACE2.45F6@delphi.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <3172ACE2.45F6@delphi.com>, S. F. Lott <slott@delphi.com> wrote:
  12.  >Ryszard Pater wrote:
  13.  >> 
  14.  >> How could I optimize for a speed the function to compute the square
  15.  >> of a floating point number?  I defined a function as follows:
  16.  >> inline float sqr(float a) {return a*a;}
  17.  >> or macro version
  18.  >> #define sqr(a) ((a)*(a)).
  19.  >> If You have a better solution give me a feed back, please.
  20.  >> 
  21.  >> Ryszard
  22.  >> pater@ireq.ca
  23.  >
  24.  >
  25.  >Note, most C compilers generate code to expand floats
  26.  >to doubles for purposes of doing arithmetic.
  27.  
  28. Floats and doubles are terminology of the C language, not the underlying
  29. implementation. Whether or not the underlying implementation supports the
  30. storage of two precisions may affect the decision about how to assign the
  31. machine's idioms to C's floats and doubles.
  32.  
  33. Fact: floating point execution units often have an even greater internal
  34. precision that is externally invisible. It may be outside of the instruction
  35. set's capabilities to specify a lower precision, so it cannot be said that the
  36. compiler can really do anything for the purposes of doing arithmetic other than
  37. generate code that prepares the operands. The internal precision used by the
  38. hardware cannot necessarily be equated with float, double or even long double.
  39. -- 
  40. I'm not really a jerk, but I play one on Usenet.
  41.